if (SERVER) then

	AddCSLuaFile( "shared.lua" )
	SWEP.Weight				= 5
	SWEP.AutoSwitchTo		= false
	SWEP.AutoSwitchFrom		= false
	SWEP.HoldType			= "rpg"

end

if ( CLIENT ) then

	SWEP.ViewModelFOV		= 62
	
	SWEP.IconFont = "HL2MPTypeDeath"
	
	SWEP.PrintName = "Aegis Cannon"
	SWEP.Slot = 0
	SWEP.Slotpos = 0
	SWEP.IconLetter = "3"
	
	killicon.AddFont( "weapon_aegiscannon", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )

end

 SWEP.Base				= "pf_base"

 SWEP.Spawnable = true;
 SWEP.AdminSpawnable = true;

 SWEP.ViewModel			= "models/weapons/v_rpg.mdl"
 SWEP.WorldModel			= "models/weapons/w_rocket_launcher.mdl"

 SWEP.Primary.Sound			=  Sound("npc/metropolice/vo/_comma.wav")
 SWEP.Primary.Recoil			= .85
 SWEP.Primary.Damage			= 1
 SWEP.Primary.NumShots		      = 0
 SWEP.Primary.Cone			= 0
 SWEP.Primary.ClipSize              = 90000;
 SWEP.Primary.Delay			= 1.65
 SWEP.Primary.DefaultClip           = 90000;
 SWEP.Primary.Automatic             = false;
 SWEP.Primary.Ammo                  = "rpg";
 SWEP.Primary.RSound			 = Sound("npc/metropolice/vo/_comma.wav")

 SWEP.Secondary.Clipsize            = -1;
 SWEP.Secondary.DefaultClip         = -1;
 SWEP.Secondary.Automatic           = false;
 SWEP.Secondary.Ammo                = "none";  
 SWEP.Secondary.Delay			= 4

/*---------------------------------------------------------
	Reload does nothing
---------------------------------------------------------*/
function SWEP:Reload()
end

/*---------------------------------------------------------
   Think does nothing
---------------------------------------------------------*/
function SWEP:Think()	
end

/*---------------------------------------------------------
	PrimaryAttack
---------------------------------------------------------*/
function SWEP:PrimaryAttack()

	local effectdata = EffectData()
		effectdata:SetOrigin( self.Owner:GetShootPos() )
		effectdata:SetEntity( self.Weapon )
		effectdata:SetStart( self.Owner:GetShootPos() )
		effectdata:SetNormal( self.Owner:GetAimVector() )
		effectdata:SetAttachment( 1 )
	util.Effect( "gunsmoke", effectdata )

	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay)
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) 		// View model animation
	self.Owner:MuzzleFlash()								// Crappy muzzle light
	self.Owner:SetAnimation( PLAYER_ATTACK1 )	
	self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )

	//local tr = self.Owner:GetEyeTrace()

	// The rest is only done on the server
	if (!SERVER) then return end
	
	util.PrecacheSound("weapons/ar2/ar2_altfire.wav")
	self.Owner:EmitSound("weapons/ar2/ar2_altfire.wav",70,math.random(100,150))
	
	--[[local rel = "vehicles/tank_readyfire1.wav" //use on the missile site
	util.PrecacheSound(rel)
	self:EmitSound(rel,70,math.random(110,135))]]
	
	local pos = self.Owner:GetPos()
	local aimvec = self.Owner:GetAimVector()
	local tracedata = {}
	tracedata.start = pos + (aimvec * 25)
	tracedata.endpos = pos + (aimvec * 90000)
	local trace = util.TraceLine(tracedata)
	
	if trace.HitNonWorld then
		if trace.Entity:IsValid() and !trace.Entity:IsPlayer() then
			self.SetTarget = trace.Entity
		end
	end
	
	local med = ents.Create( "rocket_medusamissile" )
	if ( !med:IsValid() ) then return end
	med:SetPos( self.Owner:GetShootPos() + self.Owner:GetAimVector() * 20 )
	med:SetAngles(self.Owner:GetAngles())
	med:Spawn()
	med:Initialize()
	med:Activate()
	med:SetPlayer(self.Owner)
	
	if self.SetTarget != nil then
		med:SetTarget(self.SetTarget)
		self.SetTarget = nil
	end
	
	local phys = med:GetPhysicsObject()
	if phys:IsValid() then phys:ApplyForceCenter(self.Owner:GetForward()*22000 ) end
	
	self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
	
end